﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>收入信息编辑</title>
    <link rel="stylesheet" type="text/css" href="../Content/Css/OperaMasksUI/default/om-all.css" />
    <link rel="stylesheet" type="text/css" href="../Content/Css/list.css" />
    <script type="text/javascript" src="../Scripts/jquery.1.6.3.min.js"></script>
    <script type="text/javascript" src="../Scripts/json2.js"></script>
    <script type="text/javascript" src="../Scripts/common.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/operamasks-ui.min.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/jquery.form.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/Plugin/om-yj-container.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/jquery.artDialog.js?skin=default"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/plugins/iframeTools.js"></script>
    <script type="text/javascript" src="../Scripts/banBackSpace.js"></script>
    <script type="text/javascript">
        var detailPanel, currentUID, currentBillNoID, currentBillNo, mode, detailForm, validatorForm, submitForm, showDetialForm, rowData, goOn = true;
        var actionRoot = "../handler/ajax.ashx?type=AjaxSystem", comboxBankData = [], comboxCurrencyData = [], comboxFeeTypeData = [], showToolBar;

        $(document).ready(function () {
            currentBillNoID = art.dialog.data('BillNoID');
            currentBillNo = art.dialog.data('BillNo');
            currentUID = art.dialog.data('currentUID');
            rowData = art.dialog.data('RowData');
            mode = art.dialog.data('Mode');
            detailForm = $('#viewForm');
            $(":input", detailForm).change(function () { detailForm.data('changed', true); });
            showToolBar(detailForm);
            validatorForm = $('#viewForm').validate({
                errorContainer: "#errorMessages",
                errorLabelContainer: "#errorMessages",
                wrapper: "span",
                errorClass: "omError",
                rules: {
                    BillNo: { required: true },
                    Qty: { number: true },
                    Price: { number: true },
                    FeeType: { required: true }
                },
                messages: {
                    BillNo: { required: "[账单编号]不能为空" },
                    Qty: { number: "金额必须是数字" },
                    Price: { number: "单价必须是数字" },
                    FeeType: { required: "[费用项目]不能为空" }
                }
            });
            showDetialForm("数据明细", rowData);
            $('#BillNo', detailForm).attr("readonly", true);
            switch (mode) {
                case 'new':
                    $('#UID', detailForm).val("0");
                    $('#BillNo', detailForm).val(currentBillNo);
                    $('#BillID', detailForm).val(currentBillNoID);
                    $('#Note', detailForm).val("");
                    $('span#button-saveadd', detailForm).omButton('enable');
                    $('#FeeType', detailForm).focus();
                    break;
                case 'copy':
                    $('span#button-saveadd', detailForm).omButton('disable');
                    $('#UID', detailForm).val("0");
                    $("#FeeType", detailForm).focus();
                    break;
                case 'update':
                    $('span#button-saveadd', detailForm).omButton('disable');
                    $("#FeeType", detailForm).focus();
                    break;
            };
            $("#openSelectFeeType", detailForm).click(function () {
                art.dialog.data("selectValue", 'undefined');
                art.dialog.data('SelectCode', 'D01B');
                art.dialog.open('../SystemPages/DataSelectList.aspx', {
                    id: 'DataSelectListFeeType', width: 700, height: 300, title: '选择费用项目', lock: true,
                    close: function () {
                        if (art.dialog.data("selectValue") !== 'undefined') {
                            $("#FeeType").val(art.dialog.data("selectValue"));
                        }
                    }
                }, true);
            });
        });
        showToolBar = function (form) {
            $('span#button-save', form).omButton({
                icons: { left: '../Content/Images/List/accept.png' }, width: 80,
                onClick: function () {
                    if (!detailForm.data('changed')) {
                        $.omMessageBox.alert({
                            type: 'warning',
                            title: '友情提醒',
                            content: '表单数据没有更改无需保存'
                        });
                    }
                    else {
                        if (validatorForm.form()) {
                            if (mode == 'update' && $("#UID").val() != "0") {
                                detailForm.attr("action", actionRoot + "&method=UpdateIncome");
                            }
                            else {
                                detailForm.attr("action", actionRoot + "&method=AddIncome");
                            }
                            submitForm(detailForm, function (data) {
                                if (data.IsError) {
                                    $.omMessageBox.alert({
                                        type: 'error',
                                        content: '发现错误<BR>：' + data.Message,
                                        onClose: function () {
                                            $("#FeeType", detailForm).focus();
                                        }
                                    });
                                }
                                else {
                                    $.omMessageBox.alert({
                                        type: 'success',
                                        content: '收入录入成功',
                                        onClose: function () {
                                            art.dialog.close();
                                        }
                                    })
                                }
                            });
                        }
                    }

                }
            });
            $('span#button-saveadd', form).omButton({
                icons: { left: '../Content/Images/List/ok.gif' }, width: 80,
                onClick: function () {
                    if (!detailForm.data('changed')) {
                        $.omMessageBox.alert({
                            type: 'warning',
                            title: '友情提醒',
                            content: '表单数据没有更改无需保存'
                        });
                    }
                    else {
                        if (validatorForm.form()) {
                            if (mode == 'update' && $("#UID").val() != "0") {
                                detailForm.attr("action", actionRoot + "&method=UpdateIncome");
                            }
                            else {
                                detailForm.attr("action", actionRoot + "&method=AddIncome");
                            }
                            submitForm(detailForm, function (data) {
                                if (data.IsError) {
                                    $.omMessageBox.alert({
                                        type: 'error',
                                        content: '发现错误<BR>：' + data.Message,
                                        onClose: function () {
                                            $("#FeeType", detailForm).focus();
                                        }
                                    });
                                }
                                else {
                                    $.omMessageBox.alert({
                                        type: 'success',
                                        content: '收入录入成功',
                                        onClose: function () {
                                            $('#UID', detailForm).val("0");
                                            $('#BillNo', detailForm).val(currentBillNo);
                                            $('#BillID', detailForm).val(currentBillNoID);
                                            $('#Note', detailForm).val("");
                                            $('span#button-saveadd', detailForm).omButton('enable');
                                            $('#FeeType', detailForm).focus();
                                        }
                                    })
                                }
                            });
                        }
                    }

                }
            });
            $('span#button-cancel', form).omButton({
                icons: { left: '../Content/Images/List/cross.png' }, width: 80,
                onClick: function () {
                    art.dialog.close();
                }
            });
        }

        showDetialForm = function (title, rowData) {
            if (detailPanel) {
                $("input[type=text]", detailPanel).val("");
                detailPanel.omPanel("open");
            }
            else {
                detailPanel = $('#detail-form').omPanel({
                    width: 'fit',
                    title: "<span style='color:#15428B;font-weight: bold;padding:6px;'>" + title + "</span>",
                    collapsed: false,
                    collapsible: false,
                    closable: false
                });
            }
            validatorForm.resetForm();
            rowData = rowData || {};
            $.each(rowData, function (n, value) {
                $("input[id='" + n + "']", detailPanel).val(value);
            })
        };

        submitForm = function (mainform, success, error) {
            if (!mainform)
                return false;
            else {
                mainform.ajaxSubmit({
                    type: "POST",
                    dataType: 'json',
                    success: success,
                    clearForm: false,
                    beforeSubmit: function (formData, jqForm, options) {
                        $(":checkbox,:radio", jqForm).each(function () {
                            if (!existInFormData(formData, this.name)) {
                                formData.push({ name: this.name, type: this.type, value: this.checked });
                            }
                        });
                        for (var i = 0, l = formData.length; i < l; i++) {
                            var o = formData[i];
                            if (o.type == "checkbox" || o.type == "radio") {
                                o.value = $("[name=" + o.name + "]", jqForm)[0].checked ? "true" : "false";
                            }
                        }
                    },
                    beforeSend: function (a, b, c) {
                        $.omMessageBox.waiting({
                            title: '正在保存数据中...',
                            content: '服务器正在处理请求......'
                        });
                    },
                    complete: function () {
                        $.omMessageBox.waiting("close")
                    },
                    error: function (result) {
                        $.omMessageBox.waiting("close")
                        $.omMessageBox.alert({
                            content: '发现系统错误 <BR>错误码：' + result.status
                        });
                    }
                });
            }
        }

        function existInFormData(formData, name) {
            for (var i = 0, l = formData.length; i < l; i++) {
                var o = formData[i];
                if (o.name == name) return true;
            }
            return false;
        }
    </script>
</head>
<body>
    <div id="detail-form">
        <form id="viewForm">
            <div id="errorMessages" class="error"></div>
            <table>
                <tr style="display:none;">
                    <td colspan="6">
                        <input name="UID" id="UID" value="0" />
                    </td>
                </tr>
                <tr>
                    <td align="right" style="width: 50px; ">账单编号</td>
                    <td align="left" style="width: 170px">
                        <input type="hidden" class="input-text" name="BillID" id="BillID" /><input type="text" class="input-text" name="BillNo" id="BillNo" style="width: 100%;" /></td>
                    <td align="right" style="width: 80px; margin-left: 10px;color: red;">费用项目</td>
                    <td align="left" style="width: 170px">
                        <div class="sw_b">
                            <input type="text" name="FeeType" id="FeeType" value="" /><input id="openSelectFeeType" class="sw_qbtn" type="button" />
                        </div></td>
                    <td align="right" style="width: 80px; margin-left: 10px;"></td>
                    <td align="left" style="width: 170px" colspan="2">  
                    </td>
                </tr>
                <tr>
                    <td align="right" style="width: 80px; margin-left: 10px; color: red;">单价</td>
                    <td align="left" style="width: 170px">
                        <input type="text" class="input-text" name="Price" id="Price" value="0" style="width: 100%;" />
                    </td>
                    <td align="right" style="width: 80px; margin-left: 10px;color: red;">数量</td>
                    <td align="left" style="width: 170px" colspan="2">
                        <input type="text" class="input-text" name="Qty" id="Qty" style="width: 100%;" value="1"/>
                    </td>
                    <td align="right" style="width: 80px; margin-left: 10px;"></td>
                    <td align="left" style="width: 170px" colspan="2">  
                    </td>
                </tr>
                <tr>
                    <td align="right" style="width: 50px; ">备    注</td>
                    <td align="left" style="width: 420px" colspan="3">
                        <input type="text" class="input-text" name="Note" id="Note" style="width: 100%;" maxlength="100" /></td>
                    <td align="right" style="width: 80px; margin-left: 10px;"></td>
                    <td align="left" style="width: 170px" colspan="2">  
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="6">
                        <span id="button-saveadd">保存新增</span>
                        <span id="button-save">保存</span>
                        <span id="button-cancel">取消</span>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</body>
</html>
